package linear_list.leetcode.easy;

/**
 * @author bruin_du
 * @description 删除链表的节点
 * @date 2022/5/26 19:27
 **/
public class Offer18_DeleteNode {
    public ListNode deleteNode(ListNode head, int val) {
        ListNode prev = head,cur = head;
        while(cur != null){
            if(cur.val == val){
                if(cur == head){
                    head = head.next;
                }else{
                    prev.next = cur.next;
                }
                cur.next = null;
                break;
            }
            prev = cur;
            cur = cur.next;
        }
        return head;
    }
}
